import {Loading} from "element-ui"

export default {
    install(vue) {
        let flag = null
        vue.prototype.$openLoading = opt => {
            // 只允许保留一个loading，启动前先删除
            if (flag) flag.close()
            opt = Object.assign({
                lock: true,
                text: '加载中...',
                spinner: 'el-icon-loading',
                background: 'rgba(255, 255, 255, 1)'
            }, opt)
            flag = Loading.service(opt)
        }
        vue.prototype.$closeLoading = () => {
            if (flag) flag.close()
        }
    }
}
